package serializer

import (
	"QImages/entity"
	"QImages/global"
	"QImages/utils"
)

// User 前端显示的用户信息
type User struct {
	ID        uint   `json:"id"`
	CreatedAt string `json:"created_at"`
	Username  string `json:"username"`
	Name      string `json:"name"`
	AvatarUrl string `json:"avatar_url"`
}

// BuildUser 转化为前端显示的用户信息
func BuildUser(dbUser *entity.User) User {
	var user User
	user.ID = dbUser.ID
	user.CreatedAt = utils.FormatDatetime(dbUser.CreatedAt)
	user.Username = dbUser.Username
	user.AvatarUrl = global.Config.PhotoPrefix + dbUser.AvatarUrl
	user.Name = dbUser.Name
	return user
}
